home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm1 / intsdkss.lha / include / amitcptoiw225.h next >
C/C++ Source or Header  |  1996-04-09  |  3KB  |  188 lines

  1. #ifndef AMITCP_TO_IW225
  2. #define AMITCP_TO_IW225 1
  3.  
  4. #include <proto/socket.h>
  5. #include <netinet/inetconfig.h>
  6. #include <netinet/in.h>
  7. #include <sys/syslog.h>
  8.  
  9. #define Syslog          syslog
  10. #define CloseSocket   s_close
  11. #define IoctlSocket   s_ioctl
  12. #define Errno          s_errno
  13.  
  14. #define ObtainSocket(a1,a2,a3,a4)   s_inherit ((void *) a1)
  15.  
  16. #define UNIQUE_ID (-1)
  17.  
  18. static __inline long
  19. Dup2Socket (long fd1, long fd2)
  20. {
  21.     if (fd2 == -1)
  22.     return s_dup (fd1);
  23.  
  24.     return s_dup2 (fd1, fd2);
  25. }
  26.  
  27. /*
  28. ** for ReleaseCopyOfSocket and ReleaseSocket(), the caller
  29. ** should be checking explicitly for -1, not for < 0. Otherwise,
  30. ** these can fail, if the memory on the user's machine is such
  31. ** that the negative bit (bit 31) is set...
  32. */
  33.  
  34. static __inline LONG
  35. ReleaseCopyOfSocket (LONG fd, LONG id)
  36. {
  37.     if (id == UNIQUE_ID)
  38.     {
  39.     int
  40.         newfd = s_dup (fd);
  41.     void
  42.         *val;
  43.  
  44.     if (newfd >= 0)
  45.     {
  46.         val = s_release (newfd);
  47.         if (!val)
  48.         return -1;
  49.  
  50.         return (LONG) val;
  51.     }
  52.  
  53.     return -1;
  54.     }
  55.  
  56.     return -1;
  57. }
  58.  
  59. static __inline LONG
  60. ReleaseSocket (LONG fd, LONG id)
  61. {
  62.     if (id == UNIQUE_ID)
  63.     {
  64.     void
  65.         *val = s_release (fd);
  66.  
  67.     if (!val)
  68.         return -1;
  69.  
  70.     return (LONG) val;
  71.     }
  72.  
  73.     return -1;
  74. }
  75.  
  76. static __inline LONG
  77. SetDTableSize (UWORD size)
  78. {
  79.     if (size > FD_SETSIZE)
  80.     size = FD_SETSIZE;
  81.     ConfigureInet (INET_MaxSocks, size, TAG_DONE);
  82.  
  83.     return size;
  84. }
  85.  
  86. static __inline void
  87. SetErrnoPtr (void *ptr, UBYTE size)
  88. {
  89.     if (size != 4)
  90.     {
  91.     /* ?? */
  92.     return;
  93.     }
  94.  
  95.     ConfigureInet (INET_Errno, ptr, TAG_DONE);
  96.     return;
  97. }
  98.  
  99. static __inline int
  100. countbits (unsigned long x)
  101. {
  102.     x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
  103.     x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  104.     x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F);
  105.     x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF);
  106.     x = (x & 0x0000FFFF) + ((x >>16) & 0x0000FFFF);
  107.  
  108.     return (int) (x & 255);
  109. }
  110.  
  111. static __inline int
  112. findbit (unsigned long x)
  113. {
  114.     int
  115.     i;
  116.  
  117.     for (i = 31; i >= 0; i--)
  118.     {
  119.     if (x & (1 << i))
  120.         return i;
  121.     }
  122.  
  123.     return -1;
  124. }
  125.  
  126. static __inline void
  127. SetSocketSignals (ULONG sigintrmask, ULONG sigiomask, ULONG sigurgmask)
  128. {
  129.     int
  130.     sigio  = findbit (sigiomask),
  131.     sigurg = findbit (sigurgmask);
  132.  
  133.     if (countbits (sigintrmask) != 0)
  134.     syslog (LOG_WARNING, "Sigintrmask ignored 0x%lx", sigintrmask)
  135.  
  136.     if (countbits (sigiomask) > 1)
  137.     syslog (LOG_WARNING, "Only most significant bit used in sigiomask 0x%lx", sigiomask);
  138.  
  139.     if (countbits (sigurgmask) > 1)
  140.     syslog (LOG_WARNING, "Only most significant bit used in sigurgmask 0x%lx", sigurgmask);
  141.  
  142.     ConfigureInet (INET_SignalIO, sigio, INET_SignalUrgent, sigurg, TAG_DONE);
  143.  
  144.     return;
  145. }
  146.  
  147. static __inline char *
  148. Inet_NtoA (unsigned long addr)
  149. {
  150.     struct in_addr
  151.     inaddr;
  152.  
  153.     inaddr.s_addr = addr;
  154.     return inet_ntoa (inaddr);
  155. }
  156.  
  157. static __inline unsigned long
  158. Inet_MakeAddr (long net, long lna)
  159. {
  160.     struct in_addr
  161.     inaddr = inet_makeaddr ((int) net, (int) lna);
  162.  
  163.     return inaddr.s_addr;
  164. }
  165.  
  166. static __inline long
  167. Inet_LnaOf (unsigned long addr)
  168. {
  169.     struct in_addr
  170.     inaddr;
  171.  
  172.     inaddr.s_addr = addr;
  173.     return inet_lnaof (inaddr);
  174. }
  175.  
  176. static __inline long
  177. Inet_NetOf (unsigned long in)
  178. {
  179.     struct in_addr
  180.     inaddr;
  181.  
  182.     inaddr.s_addr = in;
  183.     return inet_netof (inaddr);
  184. }
  185. #endif /* AMITCP_TO_IW225 */
  186.  
  187.  
  188.